<template>
  <view class="container">
    <view class="status-bar" :style="{ height: statusBarHeight + 'px' }"></view>
    <view class="content">
      <!-- 页面内容 -->
      <button type="primary" @click="getAltitudeFromMap">获取当前位置</button>
      <view class="location-info" v-if="locationInfo">
        <text>经度: {{ locationInfo.longitude }}</text>
        <text>纬度: {{ locationInfo.latitude }}</text>
        <text>高度: {{ locationInfo.altitude || '不支持' }}</text>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      statusBarHeight: 0,
      locationInfo: null,
      gdkey: '6ea8c7e13de9a844306775b3174e9742'
    }
  },
  onLoad() {
    uni.getSystemInfo({
      success: (res) => {
        this.statusBarHeight = res.statusBarHeight;
      }
    });
  },
  methods: {
    getLocation() {
      uni.getLocation({
        type: 'wgs84',
        altitude: true,
        isHighAccuracy: true,
        success: (res) => {
          console.log(res)
          this.locationInfo = res;
        },
        fail: (err) => {
          console.error('定位失败:', err);
          uni.showToast({
            title: '定位失败，请检查权限',
            icon: 'none'
          });
        }
      });
    },
    // 示例：使用高德地图API（需申请Key）
    getAltitudeFromMap(lng, lat) {
  uni.request({
    url: 'https://restapi.amap.com/v3/geocode/regeo',
    data: {
      key: this.gdkey,
      location: `${lng},${lat}`,
      extensions: 'all'
    },
    success: (res) => {
      console.log(res)
      const altitude = res.data.regeocode.addressComponent?.streetNumber?.height;
      console.log('地图返回高度:', altitude);
    }
  });
}



  }
}
</script>

<style>
.container {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.status-bar {
  background-color: #fff; /* 状态栏背景色 */
}

.content {
  flex: 1;
  overflow-y: auto;
}
</style>